package top.shiyiri.stream2;

import java.io.Serializable;

/**
 * @author Aunean
 * @date 2022/1/10
 */
/*
Person需要满足如下的要求，方可序列化
1.需要实现接口：Serializable
2.当前类提供一个全局常量：serialVersionUID
3.除了当前Person类需要实现Serializable之外，还必须保证其内部所有属性也
 必须是可序列化的（默认情况下，基本数据类型可序列化）

补充：ObjectOutputStream 和 ObjectInputStream 不能序列化 static 和 transient 修
饰的成员变量
 */
public class Person implements Serializable {

    private static final long serialVersionUID = -6987513259817358L;

    private static String name;
    private transient int age;
    private int id;
    private Account account;

    public Person() {
    }

    public Person(String name, int age, int id, Account account) {
        this.name = name;
        this.age = age;
        this.id = id;
        this.account = account;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", id=" + id +
                ", account=" + account +
                '}';
    }
}

class Account implements Serializable {
    private static final long serialVersionUID = -526528799939956L;

    private double balance;

    public Account(double balance) {
        this.balance = balance;
    }

    public Account() {
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    @Override
    public String toString() {
        return "Account{" +
                "balance=" + balance +
                '}';
    }
}
